<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title> 代理管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <style type="text/css">
    
  </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">  </div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <li class="layui-nav-item"><a href="{:U('Index/index')}">首页</a></li>
      <li class="layui-nav-item"><a href="{:U('InfoCate/index')}">分类信息管理</a></li>
      <li class="layui-nav-item layui-this"><a href="{:U('ShopCate/index')}">好店管理</a></li>
      <li class="layui-nav-item"><a href="{:U('Quan/index')}">同城圈管理</a></li>
      <li class="layui-nav-item"><a href="{:U('Member/index')}">用户管理</a></li>
      <li class="layui-nav-item"><a href="{:U('Home/Index/index')}">切换小程序</a></li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="{$Think.session.wechat.headimg}" class="layui-nav-img">
          {$Think.session.wechat.nickname}
        </a>
        <dl class="layui-nav-child">
          <dd><a href="{:U('Home/Index/index')}">切换小程序</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="{$Think.session.headimgurl}" class="layui-nav-img">
          {$Think.session.nickname}
        </a>
        <dl class="layui-nav-child">
          <dd><a href="{:U('Home/Public/logout')}">退出登录</a></dd>
          <!-- <dd><a href="">安全设置</a></dd> -->
        </dl>
      </li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item"><a href="{:U('ShopCate/index')}">商家分类管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Topic/index')}">专题管理</a></li>
        <li class="layui-nav-item layui-this"><a href="{:U('Shop/index')}">商家管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Shop/renlingList')}">商家认领管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Goods/index')}">商品管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Coupon/index')}">优惠券管理</a></li>
        <li class="layui-nav-item"><a href="{:U('Order/index')}">订单管理</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
      <fieldset class="layui-elem-field layui-field-title">
        <legend>商家管理</legend>
      </fieldset>
      <div style="margin-bottom: 15px;">
        <button id="add" class="layui-btn">添加商家</button>
      </div>
      <div id="view"></div>
    </div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © 2017-2018 <a href="https://www.58zltc.com" target="_blank">  </a> All Rights Reserved.
  </div>
</div>
<script id="tpl" type="text/html">
  <table class="layui-table">
    <thead>
      <tr>
        <th>ID</th>
        <th>所属分类</th>
        <th>行业模板</th>
        <th>商家名称</th>
        <th>联系人</th>
        <th>联系电话</th>
        <th>到期时间</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td>{{ item.shop_id }}</td>
        <td>{{ item.cate }}</td>
        <td>
          {{#  if(item.type == 'car'){ }}
          汽车模板
          {{#  }else if(item.type == 'jiaoyu'){ }}
          教育模板
          {{#  }else if(item.type == 'jiancai'){ }}
          建材模版
          {{#  }else{ }}
          通用模板
          {{#  } }}
        </td>
        <td>{{ item.name }}</td>
        <td>{{ item.username }}</td>
        <td>{{ item.tel }}</td>
        <td>{{ item.join_end_time }}</td>
        <td>
          {{#  if(item.is_tui == 1){ }}
          <button data-id="{{ item.shop_id }}" data-status="0" class="tui layui-btn layui-btn-small">取消推荐</button>
          {{#  }else{ }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="tui layui-btn layui-btn-small">推荐</button>
          {{#  } }}

          {{#  if(item.status == 0 ){ }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="tong layui-btn layui-btn-small">通过审核</button>
          {{#  } }}
          <button data-id="{{ item.shop_id }}" data-status="1" class="setType layui-btn  layui-btn-normal layui-btn-small">修改模板</button>

          {{#  if(item.has_mini == 0 ){ }}
          <button data-id="{{ item.shop_id }}" class="createmini" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #cccc77" >
            申请生成小程序
          </button>
          {{#  }else if(item.has_mini == 1){ }}
            <button   style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
              color: #fff;
              white-space: nowrap;
              text-align: center;border: none;
              border-radius: 2px;
              cursor: pointer;
              opacity: .9;    background-color: #92B8B1" >
              小程序生成审核中
            </button>
          {{#  }else if(item.has_mini == 2){ }}
          <button data-id="{{ item.shop_id }}" class="mini" style="height: 30px;line-height: 30px; padding: 0 10px;font-size: 12px;display: inline-block;
            color: #fff;
            white-space: nowrap;
            text-align: center;border: none;
            border-radius: 2px;
            cursor: pointer;
            opacity: .9;    background-color: #505050" >
            生成小程序
          </button>
        </td>
        {{#  } }}
      </tr>
      {{#  }); }}
      {{#  if(d.length === 0){ }}
        无数据
      {{#  } }}
    </tbody>
  </table>
  <div id="page-box"></div>
</script>
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script>
//JavaScript代码区域
layui.use(['element','laypage','laytpl','layer'], function(){
  var element = layui.element
  ,$ = layui.jquery
  ,layer = layui.layer
  ,laypage = layui.laypage
  ,laytpl = layui.laytpl;

  //推荐
  $("#view").on('click', '.tui', function(event) {
    var id = $(this).data('id');
    var status = $(this).data('status');
    $.post("{:U('tui')}", {id: id, status: status}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });
  });
  //申请生成小程序
  $("#view").on('click', '.createmini', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '生成小程序',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      skin: 'layui-layer-rim', //加上边框
      area: ['420px', '240px'], //宽高
      content: '{:U("mini")}?id='+id
    });

  })

  $("#view").on('click', '.mini', function(event) {
    var id = $(this).data('id');
    /*layer.open({
      type: 2,
      title: '生成小程序',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      skin: 'layui-layer-rim', //加上边框
      area: ['420px', '240px'], //宽高
      content: '{:U("mini")}?id='+id
    });*/
    $.get("{:U('Shop/mini')}?id="+id,function(e){
      if(e.code == 3){
        layer.alert(e.msg);
      }
      if(e.code == 1){
        parent.location.href= e.url;
      }
      if(e.code == 2){
        layer.confirm('您还没有授权，是否授权？', {
            btn: ['确认', '取消']
            ,btn2: function(index, layero){
              //请求后台关闭session
              $.get("{:U('Shop/mini')}?session=1",function(data){});
              layer.close(index);
            }
          }, function(index, layero){
            parent.location.href= e.url;
          }
        )
      }
    });

  })

  $("#add").click(function(event) {
    layer.open({
      type: 2,
      title: '添加商家',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['800px', '600px'],
      content: '{:U("add")}'
    });
  });
  $("#view").on('click', '.edit', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '编辑商家',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['800px', '600px'],
      content: '{:U("edit")}?id='+id
    });
  });
  $("#view").on('click', '.setType', function(event) {
    var id = $(this).data('id');
    layer.open({
      type: 2,
      title: '修改模板',
      shadeClose: true,
      shade: false,
      maxmin: true, //开启最大化最小化按钮
      area: ['450px', '300px'],
      content: '{:U("type")}?id='+id
    });
  });
  $("#view").on('click', '.tong', function(event) {
    var id = $(this).data('id');
    $.post("{:U('audit_shop')}", {shop_id: id}, function(e) {
      if(e.status == 1){
        layer.msg(e.info,{icon: 6,time:1000});
        setTimeout("location.reload()",1000);
      }else{
        layer.msg(e.info,{icon:1,time:1000});
      }
    });
  });

  getList(1, 10);

  function getList(page, limit){
    $.get("{:U('index')}?page="+page+"&limit="+limit,function(data){
      var view = document.getElementById('view');
      var getTpl = tpl.innerHTML;
      laytpl(getTpl).render(data.list, function(html){
        view.innerHTML = html;
      });
      laypage.render({
        elem: 'page-box'
        ,count: data.count
        ,curr: page
        ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
        ,jump: function(obj, first){
          console.log(obj)
          if(!first){
            getList(obj.curr, obj.limit);
          }
        }
      });
    })
  }  
  
});
</script>
</body>
</html>
